package com.whut.transportation;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.whut.transportation.ui.BaseActivity;
import com.whut.transportation.utils.AppManager;
/**
 * 个人信息
 * 退出
 * @author yuliyan
 *
 */
public class PersonalActivity extends BaseActivity {
	private Button updatepassword;
	private Button exit;
	private TextView name;
	
	private SharedPreferences preferences;
	
	@Override
	protected void loadViewLayout() {
		setContentView(R.layout.activity_personal);
		setTitleBarView(false, "个人信息", -1, false);
		preferences=getSharedPreferences("userId", Context.MODE_PRIVATE);
	}
	@Override
	protected void findViewById() {
		updatepassword = (Button) findViewById(R.id.updatepassword);
		exit = (Button) findViewById(R.id.exit);	
		name = (TextView) findViewById(R.id.name);
	}

	@Override
	protected void afterFindViewId() {
		
	}

	@Override
	protected void processLogic() {
		name.setText(preferences.getString("name", null));
		/*HttpRequestVo vo = new HttpRequestVo();
		vo.requestUrl = Constant.FIND_USER_INFO;
		vo.context = mContext;
		
		HashMap<String, String> req = new HashMap<String, String>();
		req.put("id", preferences.getString("id", null));
		req.put("userId", preferences.getString("userId", null));
		vo.requestDataMap = req;
		
		vo.parser = new JSONParser(StaffAndOWStaff.class);
		
		getDataFromServer(HttpManager.POST_MOTHOD, vo, 
				new DataCallback<HashMap<String, Object>>() {
					@Override
					public void onStart() {
					}
					@Override
					public void onFailed() {
						showNetErrorDialog();
					}
					@Override
					public void processData(
							HashMap<String, Object> paramObject,
							boolean paramBoolean) {
						StaffAndOWStaff staff = (StaffAndOWStaff) paramObject.get("result");
						if(!"0".equals(staff.getName()))
							name.setText(staff.getName());
						else
							name.setText("获取数据失败...");
					}
					@Override
					public void onFinish() {
						closeProgressDialog();
					}
				});*/
	}

	@Override
	protected void setListener() {
		updatepassword.setOnClickListener(this);
		exit.setOnClickListener(this);
	}

	@Override
	protected void getDataAgain() {
	}
	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.updatepassword:
			Intent intent = new Intent(this,PersonalPasswordActivity.class);
			startActivity(intent);
			break;
		case R.id.exit:
			exit();
			break;
		default:
			break;
		}
		super.onClick(v);
	}

	public void exit() {
		new AlertDialog.Builder(this)
				.setTitle("确认退出吗？")
				.setIcon(android.R.drawable.ic_dialog_info)
				.setPositiveButton("确定", new DialogInterface.OnClickListener() {
					@Override
					public void onClick(DialogInterface dialog, int which) {
						// 点击“确认”后的操作
						AppManager.getAppManager().finishAllActivity();
						android.os.Process.killProcess(android.os.Process.myPid());
						System.exit(0);
					}
				})
				.setNegativeButton("返回", new DialogInterface.OnClickListener() {
					@Override
					public void onClick(DialogInterface dialog, int which) {
					
					}
				}).show();
	}
	
}
